import sys
import os
import yaml


BASE_DIR = os.path.dirname(__file__)

# default value
# scanv ui db
CLOUDMONITOR_MONGODB = 'mongodb://127.0.0.1:27017'
CLOUDMONITOR_DB = 'cloudmonitor'
# scanv engine db
WASS_MONGODB = 'mongodb://127.0.0.1:27017'
WASS_DB = 'wass'
# scanv ui bk db
CLOUDMONITOR_MONGODB_BK = 'mongodb://127.0.0.1:27017'
CLOUDMONITOR_DB_BK = 'cloudmonitor'
SENDCLOUD = {'api_url': '', 'api_user': '', 'api_key': 'SZmBpyK6zrB2Enuj', 'fromuser': '',  'fromname': ''}
YUNPIAN = {'key': '', 'url': {'tpl': '', 'normal': ''}, 'host': 'yunpian.com', 'port': '80'}
DATETIME_FMT = '%Y-%m-%d %H:%M:%S'
DATE_FMT = '%Y-%m-%d'
MONITOR_API = {'base_url': '', 'token': ''}
SCANNER = {'base_url': '', 'SECRET_KEY': ''}
SCRIPT_LOG_DIR = "/var/log/scripts/"
ERROR_LOG_DIR = "/var/log/scripts/"
JOB_QUEUE_REDIS = {
    "host": "127.0.0.1",
    "port": 6379,
    "password": "",
    "db": 0
}
DEBUG = False
# 企业微信通知url
WX_URL = ""
# 不用监测的任务
IGNORE_TYPE = ['content', 'sitePortrait']
# 监测之前多久的任务,  单位小时
MONITOR_TIME = 12
# REDIS队列告警数
JOB_QUEUE_COUNT = 10
# REDIS可用性队列告警数
CLOUD_QUEUE_COUNT = 100
REDIS_TASK_QUEUE = ['job:default:1', 'job:cloud:1:1', 'job:cloud:1:3']
# 监测任务异常时间 单位秒
TASK_ERROR_TIME = {
    "vul": 1800,
    "ssl": 420,
    "asset": 1800,
    "securityEvent": 360,
    "content": 240,
    "sitePortrait": 60,
    "ping": 400,
    "http": 400
}

try:
    with open(os.path.join(BASE_DIR, 'settings.yaml'), 'r') as f:
        ysettings = yaml.load(f.read(), Loader=yaml.FullLoader)
except ImportError:
    print('You must have a conf/settings.yaml file', file=sys.stderr)
    sys.exit(1)

for k, v in ysettings.items():
    locals()[k] = v
